using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NCS.Module.CMS.Library;
using NCS.Library.Utilities;
using NCS.Module.CMS.Library.Definitions;
using NCS.Library;
using NCS.Module.CMS.Library.Distributions;
using NCS.Library.Components.Partner;
using NCS.Module.CMS.Library.Zones;
namespace NCS.Module.CMS.Web.Financial
{
    public partial class LeftFocusNews : CMSWebControl
    {
        public int zoneid;
        protected void Page_Load(object sender, EventArgs e)
        {
            zoneid = ConvertUtility.ToInt32(Portal[Constants.CMS_TC_Chungkhoan + AppEnv.GetLanguage()]);
            ZoneInfo info = ZoneController.GetZone(zoneid);
            hplCaption.Text = info.Zone_Name;
            hplCaption.NavigateUrl = BuildUrlByZone(zoneid, info.Portal_TabControlID);
            hplDetail.NavigateUrl = BuildUrlByZone(zoneid, info.Portal_TabControlID);
            hplMore.NavigateUrl = BuildUrlByZone(zoneid, info.Portal_TabControlID);
            DataTable focus = DistributionController.GetDistributedContents(zoneid, 1, (int)CMSDistributionRank.Special);
            if (focus.Rows.Count > 0)
            {
                int distid = ConvertUtility.ToInt32(focus.Rows[0]["Distribution_ID"]);

                hplspecial.Text = focus.Rows[0]["Content_Headline"].ToString();
                hplspecial.NavigateUrl = BuildUrlByDistId(distid, zoneid);

                string tooltip = MiscUtility.ToolTip(ConvertUtility.ToString(focus.Rows[0]["Content_Headline"]), ConvertUtility.ToString(focus.Rows[0]["Content_SubTitle"]), ConvertUtility.ToString(focus.Rows[0]["Content_Avatar"]), ConvertUtility.ToString(focus.Rows[0]["Content_Teaser"]), ConvertUtility.ToString(focus.Rows[0]["Content_Alias"]), ConvertUtility.ToDateTime(focus.Rows[0]["Distribution_CreateDate"]));
                hplspecial.Attributes.Add("onmouseover", "showtip('" + tooltip + "','322','#fcf9ea')");
                hplspecial.Attributes.Add("onmouseout", "hidetip()");
              
                if (ConvertUtility.ToString(focus.Rows[0]["Content_Avatar"]) != string.Empty)
                {
                    imgIcon.ImageUrl = MultimediaUtility.GetListAvatar(focus.Rows[0]["Content_Avatar"].ToString());
                    imgIcon.Attributes.Add("onclick", "javascript:window.location='" + BuildUrlByDistId(distid, zoneid) + "'");
                    imgIcon.Attributes.Add("style", "cursor:hand");
                }
                else imgIcon.Visible = false;
                DataTable tblist = DistributionController.GetDistributedContents(zoneid, 4, (int)CMSDistributionRank.Focus);
                rptFocusNews.DataSource = tblist;
                rptFocusNews.DataBind();
            }
        }
        protected void rptFocusNews_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView currow = (DataRowView)e.Item.DataItem;
                HyperLink hplTitle = (HyperLink)e.Item.FindControl("hplTitle");

                hplTitle.Text = ConvertUtility.ToString(currow["Content_Headline"]);

                string tooltip = MiscUtility.ToolTip(ConvertUtility.ToString(currow["Content_Headline"]), ConvertUtility.ToString(currow["Content_SubTitle"]), ConvertUtility.ToString(currow["Content_Avatar"]), ConvertUtility.ToString(currow["Content_Teaser"]), ConvertUtility.ToString(currow["Content_Alias"]), ConvertUtility.ToDateTime(currow["Distribution_CreateDate"]));
                hplTitle.Attributes.Add("onmouseover", "showtip('" + tooltip + "','322','#fcf9ea')");
                hplTitle.Attributes.Add("onmouseout", "hidetip()");

                hplTitle.NavigateUrl = BuildUrlByDistId((int)currow["Distribution_ID"], (int)currow["Distribution_ZoneID"]);
            }
        }
    }
}